<%--
  Created by IntelliJ IDEA.
  User: 林淮
  Date: 2024/12/4
  Time: 下午4:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
</head>
<script src="js/jquery3.6.4.js"></script>
<body>
<div>
    <form method="post" id="myForm" action="uploadEmp" enctype="multipart/form-data">
        <label for="email">注册邮箱:</label>
        <input type="email" name="email" id="email">&nbsp;&nbsp;
        <span id="emailText"></span><br>
        <label for="name">用户名:</label>
        <input type="text" name="name" id="name"><br>
        <label for="pwd">密码:</label>
        <input type="password" name="pwd" id="pwd"><br>
        <label>员工头像:</label>
        <input type="file" name="img" id="img"><br>
        <select name="depteid" id="depteid">
            <option value="-1">请选择部门</option>
            <c:forEach items="${depts}" var="dept">
                <option value="${dept.depteid}">${dept.name}</option>
            </c:forEach>
        </select><br>
        <input type="submit" value="注册">
    </form>
</div>
</body>
<script>
    $(function () {
        $("#email").focus(function () {
            $("#emailText").text("*").css("color", "blue");
        }).blur(function () {
            let email = $("#email").val();
            if (email === "") {
                $("#emailText").text("*").css("color", "red");
            } else {
                $.ajax({
                    url: "reg",
                    type: "post",
                    data: {
                        email: email
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.status === "error") {
                            $("#emailText").text("* " + data.msg).css("color", "red");
                        } else {
                            $("#emailText").text("* " + data.msg).css("color", "green");
                        }
                    }
                });
            }
        });
    });
</script>
</html>
